package com.dyp.rabbitmqdemo.server;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class HelloConsummer {
    @RabbitListener(queuesToDeclare = @Queue("simple"))
    public void receive(String message){
        System.out.println(message);
    }
    @RabbitListener(queuesToDeclare = @Queue("simple1000"))
    public void receive1(String message){
        System.out.println(message);
    }
    @RabbitListener(queuesToDeclare = @Queue("worker"))
    public void worker1(String message){
        System.out.println("worker1: "+ message);
    }

    @RabbitListener(queuesToDeclare = @Queue("worker"))
    public void worker2(String message){
        System.out.println("worker2: "+ message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(value=@Queue,
            exchange = @Exchange(value = "fanout", type="fanout"))
    })
    public void fanoutReceive(String message){
        System.out.println("worker1: "+ message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(value=@Queue,
                    exchange = @Exchange(value = "fanout", type="fanout"))
    })
    public void fanoutReceiveo(String message){
        System.out.println("worker2: "+ message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(value=@Queue,
                    exchange = @Exchange(value = "routing", type="direct"),
                    key = {"error", "info"})
    })
    public void routingReceive(String message){
        System.out.println("worker1: "+ message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(value=@Queue,
                    exchange = @Exchange(value = "routing", type="direct"),
                    key = {"error"})
    })
    public void routingReceiveo(String message){
        System.out.println("worker2: "+ message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(value=@Queue,
                    exchange = @Exchange(value = "topic", type="topic"),
                    key = {"user.*"})
    })
    public void topicsReceive(String message){
        System.out.println("worker2: "+ message);
    }
}

